<?php
require('functions/page_load.php');

$settings_nav = true;

if($_SERVER['REQUEST_METHOD'] == 'POST'){

	if(strlen($_FILES['image_file']['tmp_name']) > 0){
	move_uploaded_file($_FILES['image_file']['tmp_name'], '../images/banners/'.basename($_FILES['image_file']['name']));
	$image = "img = '".basename($_FILES['image_file']['name'])."',";
	}

	$sql = "INSERT INTO banners SET 
			".$image."
			code = '".mysql_real_escape_string($_POST['code'])."',
			link = '".mysql_real_escape_string($_POST['link'])."',
			placement = '".mysql_real_escape_string($_POST['placement'])."',
			published = '".mysql_real_escape_string($_POST['published'])."'";
	$query = mysql_query( $sql ) or die ("Error in query: $sql. " . mysql_error());
	$new_id = mysql_insert_id();
	
	header("Location: edit_banner.php?new=true&id=".$new_id);

}

require('includes/header.php');
?>

<div class="side_container">
<h2 class="container_header">Navigation</h2>

<ul>
<li><a href="banners.php">Banners</a></li>
<li><a href="trades.php">Trades</a></li>
<li><a href="directory_categories.php">Directory Categories</a></li>
<li><a href="subscriptions.php">Subscriptions</a></li>
<li><a href="sms_packages.php">SMS Packages</a></li>
</ul>

</div>

<div class="main_container_wrapper">

	<div class="main_container">
	<h2 class="container_header">Add Banner</h2>
	
	<div id="top_links">
	<a href="banners.php" style="background-image: url(images/back.png); padding-left: 20px;">Back to Banners</a>
	</div>
	
	<?php echo $results; ?>
	
			<form method="post" action="" enctype="multipart/form-data">
			
			<!-- user details -->
			
			<div class="form_row_wrapper">
			<div class="form_row_left"><label for="image_file">Image:</label></div>
			<div class="form_row_right"><input type="file" name="image_file" id="image_file" /><?php echo (strlen($ad_rs['image']) > 0) ? '<br /><a href="/images/banners/'.$ad_rs['image'].'" rel="prettyPhoto" style="color: #333333; font-size: 11px;">Current image</a>' : '' ; ?><br /><span style="font-size: 11px;">Image must be 468x60 for header banners or 300x250 for column banners.</span></div>
			</div>
			
			<div class="form_row_wrapper">
			<div class="form_row_left"><label for="code">Code:</label></div>
			<div class="form_row_right"><textarea name="code" id="code" style="width: 250px;"><?php echo $rs['code']; ?></textarea></div>
			</div>
			
			<div class="form_row_wrapper">
			<div class="form_row_left"><label for="link">Link:</label></div>
			<div class="form_row_right"><input type="text" name="link" id="link" value="<?php echo $rs['link']; ?>" style="width: 250px;" /></div>
			</div>

			<div class="form_row_wrapper">
			<div class="form_row_left"><label for="placement_header">Display in:</label></div>
			<div class="form_row_right"><input type="radio" name="placement" id="placement_header" value="header" /> <label for="placement_header"><span>Header</span></label><br /><input type="radio" name="placement" id="column" value="column" /> <label for="column"><span>Column</span></label></div>
			</div>
			
			<div class="form_row_wrapper">
			<div class="form_row_left"><label for="published">Published:</label></div>
			<div class="form_row_right"><input type="checkbox" name="published" id="published" value="1"<?php echo ($rs['published'] == '1') ? ' checked="checked"' : '' ; ?> /></div>
			</div>
			
			<div class="form_row_wrapper">
			<div class="form_row_left">&nbsp;</div>
			<div class="form_row_right"><input type="image" src="images/save_button.png" alt="Save" /></div>
			</div>
			
			</form>
		
	</div>

</div>
	
<?php
	require('includes/footer.php');
?>